package com.mm.controller;

import com.mm.domain.User;
import com.mm.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * 用于对非阻塞异步CompletableFuture的压力测试
 */
@RestController
public class CompletableFutureController {
    @Autowired
    private UserRepository userRepository;

    @GetMapping(value = "/testCompletableFuture")
    public CompletableFuture<List<User>> testCompletableFuture(){
        return CompletableFuture.supplyAsync(() -> {
            return userRepository.findAll();
        });
    }

    @GetMapping(value = "/testNotCompletableFuture")
    public List<User> testNotCompletableFuture(){
        return userRepository.findAll();
    }
}
